//
//  ZGSHearderView.m
//  MapleLeaf
//
//  Created by 邝子涵 on 15/12/2.
//  Copyright © 2015年 AntennaBabyTeam. All rights reserved.
//

#import "ZGSHearderView.h"

@interface ZGSHearderView ()

@end

@implementation ZGSHearderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createView];
        
    }
    return self;
}


- (void)createView{
    self.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
    self.layer.shadowOffset = CGSizeMake(0, 0);
    self.layer.shadowColor = [UIColor blackColor].CGColor;
    self.layer.shadowOpacity = 0.5;
    self.layer.shadowRadius = 1;
    
    // 头像
    self.iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 50, 50)];
    self.iconImageView.layer.borderWidth = 1;
    self.iconImageView.layer.cornerRadius = 25;
    self.iconImageView.layer.masksToBounds = YES;
    self.iconImageView.layer.borderColor = [UIColor clearColor].CGColor;
    [self addSubview:self.iconImageView];
    
    
    // 昵称
    self.nickNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(75, 20, 100, 15)];
    self.nickNameLabel.textColor = [UIColor colorWithRed:0.057 green:0.5163 blue:0.9031 alpha:1.0];
    self.nickNameLabel.font = [UIFont systemFontOfSize:14.];
    [self addSubview:self.nickNameLabel];
    
    
    // 日期label
    self.dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(75, 40, 150, 15)];
    self.dateLabel.textColor = [UIColor lightGrayColor];
    self.dateLabel.font = [UIFont systemFontOfSize:14.];
    [self addSubview:self.dateLabel];
    
    
    // 标题label
    self.contentLabelTwo = [[UILabel alloc] initWithFrame:CGRectMake(75, 60, 280, 35)];
    self.contentLabelTwo.backgroundColor = [UIColor colorWithRed:0.9211 green:0.921 blue:0.9211 alpha:0.5];
    self.contentLabelTwo.layer.borderWidth = 1;
    self.contentLabelTwo.layer.cornerRadius = 5;
    self.contentLabelTwo.layer.borderColor = [UIColor clearColor].CGColor;
    self.contentLabelTwo.layer.masksToBounds = YES;
    self.contentLabelTwo.font = [UIFont systemFontOfSize:13.];
        self.contentLabelTwo.textAlignment = NSTextAlignmentLeft;
    [self addSubview:self.contentLabelTwo];
    
    
    // 图片
    self.picImageView = [[UIImageView alloc] initWithFrame:CGRectMake(75, 95, 100, 90)];
    self.picImageView.layer.borderWidth = 1;
    self.picImageView.layer.borderColor = [UIColor clearColor].CGColor;
    self.picImageView.layer.cornerRadius = 2;
    self.picImageView.layer.shadowOffset = CGSizeMake(0, 0);
    self.picImageView.layer.shadowColor = [UIColor blackColor].CGColor;
    self.picImageView.layer.shadowOpacity = 0.8;
    self.picImageView.layer.shadowRadius = 1;
    [self addSubview:self.picImageView];
    
    
    self.numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(75, 190, 280, 20)];
    self.numberLabel.textColor = [UIColor lightGrayColor];
    self.numberLabel.font = [UIFont systemFontOfSize:12.];
    [self addSubview:self.numberLabel];
    
    
    self.footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
    
    
}


// set方法赋值
- (void)setModel:(ZGSDetaileModel *)model{
    if (_model != model) {
        _model = model;
    }
    
    self.contentLabelTwo.text = model.content;
    self.contentLabelTwo.numberOfLines = 0;
    [self.contentLabelTwo sizeToFit];

    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.icon] placeholderImage:nil];
    
    self.nickNameLabel.text = model.nickName;
    
    //时间
    NSDate *lastDate = [NSDate dateWithTimeIntervalSince1970:[model.sendTime integerValue] / 1000];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"YYYY-MM-dd hh:mm"];
    NSString *time = [df stringFromDate:lastDate];
    self.dateLabel.text = time;
    
    
    NSString *url = [model.pic componentsSeparatedByString:@","][0];
    [self.picImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:nil];
    
    self.numberLabel.text = [NSString stringWithFormat:@" 阅读: %@    评论: %@    赞: %@", model.readCount, model.reCount, model.upCount];
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
